/*
	Copyright (c) 2012 by karmaleaving@qq.com. All rights RESERVED.
*/
#ifdef _KL_USE_ORDER_SEEKER_
#include "memory.h"

template<typename Iterator, typename Value = typename iterator_traits<Iterator>::value_type>
struct _order_seeker_
{
	public:
		KL_TYPE_DEFINE(Value);
		typedef Iterator iterator;
		typedef _iterator_helper_<iterator> _i_helper;
		typedef _memory_helper_<value_type> _helper;
	protected:
	public:
		template<typename Less>
			static iterator linear_lower_bound(iterator first, iterator last, value_type const &value, Less fun)
			{
				for(; first != last; ++first)
				{
					if(fun(*first, value)) continue;
					break;
				}
				return first;
			}	
		template<typename Less>
			static iterator linear_upper_bound(iterator first, iterator last, value_type const &value, Less fun)
			{
				for(; first != last; ++first)
				{
					if(fun(value, *first)) break;
				}
				return first;
			}
		template<typename Less>
			static bool linear_search(iterator const &first, iterator const &last,
					value_type const &value, Less fun)
			{
				iterator result = linear_lower_bound(first, last, value, fun);
				return (result != last && !fun(value, *result));
			}
};
#endif // _KL_USE_ORDER_SEEKER_
